package com.contract.management.bean.page;

import java.util.ArrayList;
import java.util.List;

public class PageResult {
	
	//总记录数
	private long totalCount;
	
	//总页数
	private int totalPage;
	
	//当前页
	private int curPage;
	
	//每页记录数
	private int pageSize;
	
	//记录
	private List<Object[]> data = new ArrayList<>();

	
	public PageResult() {
	}

	
	public PageResult(long totalCount, int curPage, int pageSize) {
		this.totalCount = totalCount;
		this.curPage = curPage < 1 ? 1 : curPage;
		this.pageSize = pageSize;
		totalPage =  (int)Math.ceil(totalCount / (float)pageSize);
		if(totalPage < 1) totalPage = 1;
		if(curPage > totalPage) curPage = totalPage;
		
	}
	
	public int getFirstResult() {
		return (this.curPage - 1) * this.pageSize;
	}
	
	public PageResult(List<Object[]> data) {
		this.data = data;
		this.totalCount = data.size();
		this.pageSize = (int)this.totalCount;
	}


	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public List<Object[]> getData() {
		return data;
	}

	public void setData(List<Object[]> data) {
		this.data = data;
	}
}
